package com.lry.jvm.instructions.loads;

import com.lry.jvm.instructions.base.Index8Instruction;
import com.lry.jvm.instructions.base.NoOperandsInstruction;
import com.lry.jvm.rtda.Frame;
import com.lry.jvm.rtda.JObject;
import com.lry.jvm.rtda.OperandStack;
import com.lry.jvm.util.Util;

public class daload extends NoOperandsInstruction {
    @Override
    public byte getOpCode() {
        return 0x31;
    }

    @Override
    public void execute(Frame frame) {
        OperandStack stack = frame.getOperandStack();
        int index = stack.popInt();
        JObject arrRef = stack.popRef();
        if(null==arrRef){
            Util.panic("java.lang.NullPointerException");
        }
        double[] shorts = arrRef.toDoubles();
        if(index<0||index>=shorts.length){
            Util.panic("ArrayIndexOutOfBoundsException");
        }

        stack.pushDouble(shorts[index]);
    }
}
